package com.gitee.somenvm.ninerpgitem.compat

import ac.github.oa.internal.core.item.ItemPlant
import ink.ptms.um.Mythic
import org.bukkit.Bukkit
import org.bukkit.entity.LivingEntity
import org.bukkit.inventory.ItemStack

/**
 * BY NineRpgItem
 * com.gitee.somenvm.ninerpgitem.compat
 *
 * @author  SomeNvM
 * @date  2023/1/16 22:55
 */
object StoreItemControl {
    private val mmOnLoad: Boolean
        get() = Bukkit.getPluginManager().isPluginEnabled("MythicMobs")
    private val oaOnLoad: Boolean
        get() = Bukkit.getPluginManager().isPluginEnabled("OriginAttribute")

    fun getMythicItemStack(id: String): ItemStack? {
        if (isMythicItem(id)) {
            return Mythic.API.getItemStack(id) ?: error("MM物品 $id 配置错误")
        }
        return null
    }

    fun isMythicItem(id: String): Boolean {
        if (!mmOnLoad) return false
        return id in Mythic.API.getItemIDList()
    }

    fun getOAItemStack(entity: LivingEntity?, id: String): ItemStack? {
        if (!oaOnLoad) return null
        if (ItemPlant.hasKey(id)) {
            return ItemPlant.build(entity, id) ?: error("OA物品 $id 配置错误")
        }
        return null
    }
}